package com.mvp.shq.washer.ui.coupon;

import com.mvp.shq.washer.entity.result.BaseResult;
import com.mvp.shq.washer.entity.result.CouponResult;
import com.mvp.shq.washer.http.BaseObserver;
import com.mvp.shq.washer.utils.SpUtil;

/**
 * Created by Administrator on 2017/8/24.
 */

public class CouponPresenter extends CouponConstract.Presenter {
    @Override
    public void onStart() {

    }

    @Override
    void coupons(int pageNo,int pageSize) {
        String token = SpUtil.getToken();
        String userId = SpUtil.getUser().getId();
        model.coupons(token,userId,pageNo,pageSize)
                .subscribe(new BaseObserver<CouponResult>(view) {
                    @Override
                    protected void onSuccees(BaseResult<CouponResult> t) throws Exception {
                        if (t.isError()){
                            view.couponsF(t.getMsg());
                        }else {
                            view.couponsS(t.getData().getList());
                        }
                    }

                    @Override
                    protected void onFailure(Throwable e, boolean isNetWorkError) throws Exception {
                        e.printStackTrace();
                        view.couponsF("未知错误");
                    }
                });
    }
}
